<?php

namespace Sharks\Core\Make;

use Sharks\Core\AppContext;
use Sharks\Core\Module;
use Sharks\Core\Cfg\AppConfig;
use Sharks\Core\LifeCycle\Event;
use Sharks\Core\Support\Storage\ArrayLoader;
use Sharks\Core\Support\Storage\StorageArrayUtils;

/**
 * 事件初始化
 * 依赖：
 * 		ModuleMaker
 */
class EventMaker extends Maker {

	public function dev(AppContext $app) {
		$appEventPath = $app->path()->app->source . "/Resource/events.php";
		if (file_exists($appEventPath)) {
			require_once ($appEventPath);
		}

		$frameworkEventPath = $app->path()->framework->root . "/events.php";
		if (file_exists($frameworkEventPath)) {
			require_once ($frameworkEventPath);
		}

		foreach (Module::all() as $module) {
			if (file_exists($module->path()->resource . '/events.php')) {
				require_once ($module->path()->resource . '/events.php');
			}
		}
	}
	
	public function server(AppContext $app) {
		$events = ArrayLoader::load($app->path()->app->storage . '/events.php', array());
		Event::setEvents($events);
	}

	public function makers() {
		return array(ModuleMaker::class);
	}
}